package com.example.dllo.my36kr.drawer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/8/18.
 * Activity中抽屉的Adapter
 */
public class DrawerAdapter extends BaseAdapter {
    ArrayList<DrawerBean>list;
    Context mContext;

    public DrawerAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setList(ArrayList<DrawerBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DrawerViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.drawerlayout_item,null);
            holder = new DrawerViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (DrawerViewHolder) convertView.getTag();
        }
        holder.drawerTv.setText(list.get(position).getName());
        holder.picIv.setImageResource(list.get(position).getBitmap());
        return convertView;
    }
    public class DrawerViewHolder{
        TextView drawerTv;
        ImageView picIv;
        public DrawerViewHolder(View view) {
            drawerTv = (TextView) view.findViewById(R.id.tv_drawer_item);
            picIv = (ImageView) view.findViewById(R.id.iv_main_drawer);
        }
    }
}
